// Widgets/Protocol/ProtocolType/ProtocolType.js
import { queryAppInforMation } from '../../../api/brand';
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    paymentMode: {
      type: String,
      value: '',
    },
    repaymentMode: {
      type: String,
      value: '',
    }
  },
  options: {
    styleIsolation: 'shared',
  },
  lifetimes: {
    attached: function() {
      let _this = this;
      this._getPaymentMode();
      this._getRepaymentMode();
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    paymentModeList: [],
    showPaymentMode: false,
    repaymentModeList: [],
    showRepaymentMode: false,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 获取支付方式
    _getPaymentMode(){
      let _this = this;
      queryAppInforMation({infoType: '10',page: 0,size: 99})
      .then(res => {
        if(res.success){
          var arr = [];
          for (let index = 0; index < res.data.content.length; index++) {
            const element = res.data.content[index];
            arr.push(element.content);
          }
          _this.setData({
            paymentModeList: arr,
          })
        }else{
          wx.showToast({
            title: res.errMessage,
            icon: 'none'
          })
        }
      })
    },
    // 获取还款方式
    _getRepaymentMode(){
      let _this = this;
      queryAppInforMation({infoType: '11',page: 0,size: 99})
      .then(res => {
        if(res.success){
          var arr = [];
          for (let index = 0; index < res.data.content.length; index++) {
            const element = res.data.content[index];
            arr.push(element.content);
          }
          _this.setData({
            repaymentModeList: arr,
          })
        }else{
          wx.showToast({
            title: res.errMessage,
            icon: 'none'
          })
        }
      })
    },
    selPaymentMode(){
      this.setData({showPaymentMode: true})
    },
    selRepaymentMode(){
      this.setData({showRepaymentMode: true});
    },
    onClose(){
      this.setData({showPaymentMode: false,showRepaymentMode: false})
    },
    onConfirm(e){
      const { picker, value, index } = e.detail;
      this.triggerEvent('updateValue',{'data': value,'name': 'paymentMode'})
      this.onClose();
    },
    onConfirmRepaymentMode(e){
      const { picker, value, index } = e.detail;
      this.triggerEvent('updateValue',{'data': value,'name': 'repaymentMode'})
      this.onClose();
    }
  }
})